package es.ubu.ceudaaj.exercise.ud02.t04.l03;

import java.awt.BorderLayout;
import java.awt.FlowLayout;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;

import javax.swing.JButton;
import javax.swing.JDialog;
import javax.swing.JFrame;
import javax.swing.JPanel;

@SuppressWarnings("serial")
public class CreateContactDialog extends JDialog {
	
	public ContactDataPanel contactDataPanel;
	public boolean crearContacto = false;
	
	public CreateContactDialog(JFrame frame){
		super(frame,true);
		setDefaultCloseOperation(JDialog.DISPOSE_ON_CLOSE);

		contactDataPanel = new ContactDataPanel();
		getContentPane().add(contactDataPanel, BorderLayout.CENTER);
		
		JPanel panel = new JPanel();
		FlowLayout flowLayout = (FlowLayout) panel.getLayout();
		flowLayout.setAlignment(FlowLayout.RIGHT);
		getContentPane().add(panel, BorderLayout.SOUTH);
		
		JButton btnCrear = new JButton("Crear Contacto");
		btnCrear.addActionListener(new BtnCrearActionListener());
		panel.add(btnCrear);
		
		JButton btnCancelar = new JButton("Cancelar");
		btnCancelar.addActionListener(new BtnCancelarActionListener());
		panel.add(btnCancelar);
		
		this.setSize(400,300);
		this.setVisible(true);
	}

	private class BtnCrearActionListener implements ActionListener {
		public void actionPerformed(ActionEvent e) {
			crearContacto = true;
			setVisible(false);
		}
	}
	private class BtnCancelarActionListener implements ActionListener {
		public void actionPerformed(ActionEvent e) {
			setVisible(false);
		}
	}
}
